<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!--准备好一个容器-->
    <div id="test"></div>
    
    <!---引入react核心库-->
    <script type="text/javascript" src="./js/react.development.js"></script>
    <!--引入react-dom用于支持react操作dom-->
    <script type="text/javascript" src="./js/react-dom.development.js"></script>
    <!--引入babel用于将jsx转为js-->
    <script type="text/javascript" src="./js/babel.min.js"></script>
    <script type="text/javascript" src="./js/prop-types.js"></script>

    <script type="text/babel"> //此处一定要写
        
        class Demo extends React.Component{

            state = {isHot:true}
            
            showInfo=()=>{
                const {input1} = this
                alert(input1.value)
            }
            changeWeather=()=>{
                const {isHot} = this.state
                this.setState({isHot:!isHot})
            }
            
            saveInput=(c)=>{
                this.input1=c
                console.log('#')
            }

            render(){
                const {isHot} = this.state

                //内联函数在state被更新时，会被调用两次，第一次调用传入的参数为null，第二次会传入DOM元素参数
                //不用内联函数则只会被调用一次 但是没啥影响 一般就写成内联函数
                return(
                <div>
                    <h2>今天天气很{isHot?'热':'冷'}</h2>
                    {/*<input ref={(c)=>{this.input1=c;console.log('#')}} type="text"/>*/}
                    <input ref={this.saveInput} type="text"/>
                    <button onClick={this.showInfo}>点击显示信息</button>
                    <button onClick={this.changeWeather}>点我切换天气</button>
                </div>
                )
            }

        }
    ReactDOM.render(<Demo/>,document.getElementById("test"))
    </script>
</body>
</html>